/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package validation;

import bean.Kreditgeber;
import java.util.List;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class DoubleNameCheckValidator implements ConstraintValidator<DoubleNameCheck, List<Kreditgeber>> {

    @Override
    public void initialize(DoubleNameCheck a) {
    }

    @Override
    public boolean isValid(List<Kreditgeber> t, ConstraintValidatorContext cvc) {
        for(int i=0; i<t.size()-1; i++) {
            Kreditgeber kg1 = t.get(i);
            for(int j=i+1; j<t.size(); j++) {
                Kreditgeber kg2 = t.get(j);
                if(kg1.getName().equals(kg2.getName())) {
                    //hat hier nix zu suchen
                    t.remove(kg2); //Änderung rückgängig machen
                    return false;
                }
                
            }
        }
        return true;
    }
    
}
